<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit>
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">
                        <a-button  @click="getCacheList">{{$ti18('rxList.refreshBtn','刷新')}}</a-button>
                        <a-button v-if="selectedRows && selectedRows.length>0" type="danger" @click="del(selectedRows)">{{$ti18('rxList.delBtn','删除')}}</a-button>
                    </div>
                </div>
                <rx-grid
                    ref="table"
                    :allowRowSelect="true"
                    :columns="columns"
                    :dataSource="dataSource"
                    :bordered="true"
                    :showPage="false"
                    :multiSelect="true"
                    @selectChange="onSelectChange"
                >
                <span slot="action" slot-scope="{ text, record }" class="actionIcons">
                    <span @click="del([record])">{{$ti18('rxList.delBtn','删除')}}</span>
                  </span>
                </rx-grid>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
import {RxLayout,RxGrid,RxFit,BaseList} from "@lowcode/jpaas-common-lib";
import CacheManageApi from "@/api/system/core/cacheManage.js"

export default {
    name: "CacheManage",
    components:{
        RxLayout,
        RxGrid,
        RxFit
    },
    mixins:[BaseList],
    data() {
        return {
            dataSource:[],
            columns:[
                {title: this.$ti18('rxList.index','序号'), type: 'indexColumn', width: 60, dataIndex: 'serial', scopedSlots: {customRender: 'serial'}},
                {title: this.i18n('form.key','缓存Key'), dataIndex: 'key', width: 150},
                {title: this.$ti18('rxList.action','操作'), width: 100, dataIndex: 'action', scopedSlots: {customRender: 'action'}}
            ],

        }
    },
    created() {
        this.getCacheList();
    },
    methods: {
        i18n(name,text,key){
            return this.$ti18(name,text,"CacheManage",key);
        },
        getCacheList(){
            CacheManageApi.getCacheList().then(res=>{
                if(res && res.success){
                    this.dataSource=res.data;
                }
            });
        },
        del(selectedRows){
            let self_ = this;
            this.$confirm({
                title: this.$ti18('rxMsa.actionTips','操作提示'),
                zIndex: 20000,
                content: this.$ti18('rxMsa.delInfo','您确定需要删除选中的记录吗？'),
                okText: this.$ti18('rxForm.ackBtn','确认'),
                cancelText: this.$ti18('rxForm.cancelBtn','取消'),
                onOk() {
                    var keys=[];
                    selectedRows.find(item=>{
                        keys.push(item.key);
                    })
                    CacheManageApi.removeCache(keys).then(res=>{
                        self_.selectedRows=[];
                        self_.getCacheList();
                    });
                },
                onCancel() {
                }
            })
        }
    },
    watch: {}
}
</script>

<style scoped>
</style>